/************************************table点击弹出下拉快捷菜单控件 开始***********************************/
$.fn.jefActionRow = function (opt) {
	var eventIndex = -1;
    return this.each(function (i) {
        var CONTROL = this; 	//本控件容器
        CONTROL.option = {
            /***********可配置内容(可扩展)************/
        	dragType:'cookie',				//启用cookie记录拖拽保存宽度以及字段列的隐藏或者关闭
        	key:'-1',						//必填,用于区分当前页面唯一标识通常使用currentMenuId
        	autoSize:true,					//是否启用grid自适应屏幕滚动效果
        	dragSize:true,					//是否启用grid头拖拽控制列宽
        	configColumn:true,				//是否启用隐藏列设置
            selectedClass: "jefActionRow", //选中行样式
            floatMenuDivClass: "jefActionRow_RightMenu",//浮动菜单样式
            menuItemHoverClass: "jefActionRow_HoverItem",//菜单项悬浮样式
            exceptFirstRow:	false,			//为true则第一个tr标签为顶部说明行，该行不添加单击事件	
            exceptLastRow:	true,			//为true则最后一个tr标签为分页行，该行不添加单击事件
           	doubleClick: 0,					//双击默认执行第一个item的事件，若不要单击事件可设置为-1
            items: null,					//快捷菜单内容
            overHide: true,					//为true时td中超长内容自适应隐藏
            autoCreateItem: true,			//由于jef框架，不用设置items自动判断隐藏原按钮，并且添加下拉事件,改为false可用于其他框架的table
            /***********items 例子 开始**************
            items:[{name:"查看",click:function(row){select(row.attr("source"))}},
			{name:"删除",click:function(eventRow){alert(eventRow);},judge:function(eventRow){if(eventRow.attr("isShow"))return true; else return false;}}]
            ***********items 例子 结束**************/
            /**********事件*************/
            
            afterInit: false//初始化完成后执行
            /*********可扩展自定义属性或方法********/
        };
        CONTROL.option = $.extend(CONTROL.option, opt);
        
        CONTROL.hideConfigColumn=function (){
			$("#divAjax,#divAjaxBG").hide();
		}
        
		CONTROL.showConfigColumn=function (){
			var width = $(window).width();
			var height = $(window).height();
			if($("body:first").width()>width)
				width=$("body:first").width();
			if($("body:first").height()>height)
				height=$("body:first").height();
			$("#divAjaxBG").height(height).width(width).show();
			//初始化数据
			var display='<table cellpadding="0" cellspacing="0" width="100%" table="left"><tr><th style="background-color:#eeeeee;border-bottom:dashed 1px gray;">显示列</th></tr>';
			var hidden='<table cellpadding="0" cellspacing="0" width="100%" table="right"><tr><th style="background-color:#eeeeee;border-bottom:dashed 1px gray;">隐藏列</th></tr>';
			$("tr:first strong",gridHead).each(function(){
				if($(this).html()=="操作"){
					return;
				}
				var td=$(this).parent();
				if(td.is(":visible"))
					display+='<tr><td style="border-bottom:dashed 1px gray;" index="'+td.attr("index")+'" i="'+td.attr("i")+'" d="0">'+$(this).html()+'</td></tr>';
				else
					hidden+='<tr><td style="border-bottom:dashed 1px gray;" index="'+td.attr("index")+'" i="'+td.attr("i")+'" d="1">'+$(this).html()+'</td></tr>';
			});
			$("#divAjax [box='left']:first").html(display+'</table>');
			$("#divAjax [box='right']:first").html(hidden+'</table>');
			$("#divAjax table[table]").nfpDrag({initBorder:"dashed 1px gray",afterDblClick : function(eventTd){
				var target = eventTd.parents("table:first").attr("table");
				eventTd.parent().appendTo($("#divAjax table[table='"+(target=="left" ? "right":"left")+"']:first"));
			}});
			$("#divAjax").height(height-150).css({"top":75+"px","left":(width-$("#divAjax").width()-10)/2+"px"}).show().find("[box]").height(height-160-$("#divAjax [button]:first").height());
		}
		
		CONTROL.orderCookie=function(){
			var cookieName=CONTROL.option.key;
			var cookieValue=CONTROL.getCookie(cookieName);
			var newValue="";
			var orderArray=new Array(0);
			$("tr:first td",gridHead).each(function(){
				if($(this).children("strong:first").html()=="操作")
					return;
				var obj = {o:$(this).attr("i"),i:$(this).attr("index")};
				if(!$(this).is(":visible")){
					//需要记录隐藏
					obj.d="1";
				}
				orderArray[orderArray.length]=obj;
			});
			if(cookieValue!=""){
				//需要判断连接之前的值
				var cookieArray=new Array(0);
				try{
					cookieArray=eval(cookieValue.replace(/@/g, ","));
				}catch(exception){}
				for(var i=0;i<cookieArray.length;i++){ 
					var source=cookieArray[i];
					var isFind=false;
					for(var j=0;j<orderArray.length;j++){
						var temp =orderArray[j];
						if(source.w && temp.i==source.i){
							isFind=true;
							temp.w=source.w;
							break;
						}
					}
					if(!isFind && source.w){
						orderArray[orderArray.length]={i:source.i,w:source.w};
					}
				}
			}
			for(var i=0;i<orderArray.length;i++){
				var source=orderArray[i];
				newValue+=(i==0?"":"@")+"{i:"+source.i;
				if(source.w)
					newValue+="@w:"+source.w;
				if(typeof(source.o)!="undefined")
					newValue+="@o:"+source.o;
				if(source.d)
					newValue+="@d:"+source.d;
				newValue+="}";
			}
			if(newValue!=""){
				document.cookie=cookieName+"=["+newValue+"];path=/;expires=Sun, 05 Nov 10000 06:25:40 GMT";
			}
			else if(cookieValue!="")
				CONTROL.deleteCookie(CONTROL.option.key);
		};
        
        CONTROL.putCookie=function(putTd){
        	var index=putTd.attr("index");
        	var width=putTd.width();
			var cookieName=CONTROL.option.key;
			var cookieValue=CONTROL.getCookie(cookieName);
			if(cookieValue!=""){
				//需要连接之前的值
				var cookieArray=new Array(0);
				try{
					cookieArray=eval(cookieValue.replace(/@/g, ","));
				}catch(exception){}
				var newValue="";
				for(var i=0;i<cookieArray.length;i++){ 
					var source=cookieArray[i];
					if(source.i!=index){
						newValue+="{i:"+source.i;
						if(source.w)
							newValue+="@w:"+source.w;
						if(typeof(source.o)!="undefined")
							newValue+="@o:"+source.o;
						if(source.d)
							newValue+="@d:"+source.d;
						newValue+="}@";
					}
				}
				cookieValue=newValue;
			}
			document.cookie=cookieName+"=["+cookieValue+"{i:"+index+"@w:"+width+"@o:"+putTd.attr("i")+"}];path=/;expires=Sun, 05 Nov 10000 06:25:40 GMT";
        }
        
        CONTROL.getCookie=function(cookieName){
        	var cookieString=document.cookie;
			var cookieValue="";
			if(cookieString!=null && cookieString!=""){
				var cookieArray=cookieString.split("; "); 
				for(var i=cookieArray.length-1;i>=0;i--){ 
					var array=cookieArray[i].split("="); 
					if(array[0]==cookieName){
						cookieValue=array[1];
						break;
					} 
				}
			}
			return cookieValue;
        }
        var moveHead=false;
        var movePager=false;
        var moveSum=false;
        var pager=null;
        var trSum=null;
        var head=null;
        var gridHead=null;
        var gridTable=null;
        CONTROL.refreshHeight=function (){
			var tableHeight=$(window).height()-40;
			tableHeight -=$(".info_right_tab:first").size()==0 ? 0 : $(".info_right_tab:first").height();
			tableHeight -=$(".info_right_ctrl:first").size()==0 ? 0 : $(".info_right_ctrl:first").height();
			if(movePager)
				tableHeight-=pager.height();
			if(moveSum)
				tableHeight-=trSum.height();
			if(moveHead)
				tableHeight-=head.height();
			$("#divGrid").height(tableHeight);
		}
        
        CONTROL.refreshWidth=function (){
        	var tableWidth=0;
        	$("#"+(moveHead?"gridHead":"gridTable")+" tr:first").children(":visible").each(function(index){
				tableWidth+=$(this).attr("width").indexOf("%")==-1 ? parseInt($(this).attr("width")):$(this).width();
			});
			$("#gridTable,#gridHead table:first").css("width",tableWidth+"px");
        };
        
        CONTROL.orderColumn=function(){
        	var max = CONTROL.option.maxIndex;
        	for(i=0;i<=max;i++){
        		var td=$("tr:first td[o='"+i+"']:first",gridHead);
        		if(td.size()==1){
        			CONTROL.moveColumn(td);
        		}
        	}
        	CONTROL.refreshSize();
        }
        
        CONTROL.moveColumn=function(td){
        	var newIndex = td.attr("o");
        	var oldIndex = td.attr("i");
        	if(newIndex!=oldIndex){
        		var i=parseInt(newIndex);
        		//需要排序
        		if(newIndex=="0"){
        			$("tr:first td:first",gridHead).before(td);
        			if(gridTable!=null){
	        			$("tr",gridTable).each(function(){
	        				var tds = $(this).find("td");
							$(tds[0]).before($(tds[oldIndex]));
						});
        			}
					if(trSum!=null){
						var tds = trSum.find("td");
						$(tds[0]).before($(tds[oldIndex]));
					}
        		}else{
        			$("tr:first td:eq("+(i-1)+")",gridHead).after(td);
        			if(gridTable!=null){
        				$("tr",gridTable).each(function(){
	        				var tds = $(this).find("td");
							$(tds[i-1]).after($(tds[oldIndex]));
						});
        			}
					if(trSum!=null){
						var tds = trSum.find("td");
						$(tds[i-1]).after($(tds[oldIndex]));
					}
        		}
        		$("tr:first td",gridHead).each(function(c){
        			$(this).attr("i",c);
        		});
        	}
        	td.removeAttr("o");
        }
        
        CONTROL.deleteCookie=function(cookieName){
        	var expires = new Date();
			expires.setTime(expires.getTime() - 1);
			document.cookie = cookieName+'=1;path=/;expires=' + expires.toGMTString();
        }
        
        CONTROL.changeColumn=function(eventTd,isShow){
        	if(isShow)
        		eventTd.show();
        	else
        		eventTd.hide();
			var index = eventTd.attr("i");
			if(gridTable!=null){
				$("tr",gridTable).each(function(){
					if(isShow)
						$(this).find("td:eq("+index+")").show();
					else
						$(this).find("td:eq("+index+")").hide();
				});
			}
			if(trSum!=null){
				if(isShow)
					trSum.find("td:eq("+index+")").show();
				else
					trSum.find("td:eq("+index+")").hide();
			}
        }
        
        CONTROL.refreshSize=function(){
        	var maxAutoWidth = $("td[width]:first",gridTable).attr("width").indexOf("%") == -1;
			if(maxAutoWidth){
				CONTROL.refreshWidth();
				CONTROL.refreshHeight();
			}
        }
        
        CONTROL.showMenu = function(e,isHead){
        	var menuItems = CONTROL.option.items;
        	if(!isHead && !CONTROL.option.autoCreateItem && (menuItems==null || menuItems.length==0))
        		return;
			var rightMenu= $("#jefActionRow_RightMenu");
			var itemsHtml = "";
			if(isHead){
				var eventTd = $("tr:first ."+CONTROL.option.selectedClass+":first",gridHead);
				rightMenu.html('<div type="hide">隐藏该列</div><div type="all">配置所有列</div>').children().hover(function(){
					$(this).addClass(CONTROL.option.menuItemHoverClass);
				},function(){
					$(this).removeClass(CONTROL.option.menuItemHoverClass);
				}).click(function(e){
					$("#jefActionRow_RightMenu").hide();
					$("."+CONTROL.option.selectedClass).removeClass(CONTROL.option.selectedClass);
					e.stopPropagation();
					if($(this).attr("type")=="hide"){
						if($("tr:first td:visible",gridHead).size()==1){
							j_tip("该列无法隐藏，至少得保证有一列显示", 'error');
							return;
						}
						CONTROL.changeColumn(eventTd);
						CONTROL.refreshSize();
						if(CONTROL.option.dragType=='cookie'){
							CONTROL.orderCookie();
						}
					}else if($(this).attr("type")=="all"){
						CONTROL.showConfigColumn();
					}
				});
			}
			//一个页面初始化多个控件，点击弹出不同的快捷菜单
			else if(CONTROL.option.autoCreateItem || eventIndex!=i){
				var eventTr = gridTable.find("."+CONTROL.option.selectedClass+":first");
				if(CONTROL.option.autoCreateItem){
					//为框架专门写的控件代码，由原按钮格式变为现在的点击出现下拉菜单执行begin
					var buttons = eventTr.find("input[type='button'][onclick]");
					if(buttons.size()==0)
						return;
					buttons.each(function(){
						itemsHtml += "<div onclick='"+$(this).attr("onclick")+"'>"+$(this).val()+"</div>";
					});
					//为框架专门写的控件代码，由原按钮格式变为现在的点击出现下拉菜单执行end
				}else{
					for(var j=0;j<menuItems.length;j++){
						if(typeof(menuItems[j].judge)!="function" || menuItems[j].judge(eventTr))
							itemsHtml += "<div type='"+j+"'>"+menuItems[j].name+"</div>";
					}
				}
				rightMenu.html(itemsHtml).children().hover(function(){
					$(this).addClass(CONTROL.option.menuItemHoverClass);
				},function(){
					$(this).removeClass(CONTROL.option.menuItemHoverClass);
				}).click(function(e){
					$("#jefActionRow_RightMenu").hide();
					e.stopPropagation();
					if(!CONTROL.option.autoCreateItem){
						var index = parseInt($(this).attr("type"));
						if(typeof(menuItems[index].click) == "function"){
							menuItems[index].click(eventTr);
						}
					}
				});
				eventIndex=i;
			}
			rightMenu.children().removeAttr("style").last().css("border","none");
			//自动初始化开始坐标
        	var overX=(e.pageX+5);
        	var overY=(e.pageY+5);
        	var menuWidth = rightMenu.width()+5;
        	var menuHeight = rightMenu.height()+5;
			if(e.pageX+menuWidth>=$(window).width())
				overX=e.pageX-menuWidth;
			if(e.pageY+menuHeight>=$(window).height())
				overY=e.pageY-menuHeight;
			rightMenu.css({"left":overX+"px","top":overY+"px"}).show();
        };
		
        //初始化grid内容
        CONTROL.initGrid = function(){
        	var maxAutoWidth = $("td[width]:first",gridHead).attr("width").indexOf("%") == -1;
        	gridTable = $("#gridTable").width(gridHead.find("table:first").width());
        	var firstTr = $("tr[onMouseMove]:first",gridTable);
        	var tds = firstTr.children("td");
			if(firstTr.size()==0){
				//无数据
				var tdHtml = '';
				head.children().each(function(){
					tdHtml+='<td width="'+$(this).attr("width")+'" style="border:none;'+($(this).is(":visible")?'':'display:none')+'">&nbsp;</td>';
				});
				if(gridTable.find("tr:first").size()==0)
					gridTable.append('<tr height="30">'+tdHtml+'</tr>');
				else
					gridTable.find("tr:last").before('<tr height="30">'+tdHtml+'</tr>');
			}else{
				var trs = $("tr",gridTable);
				tds.each(function(i){
					$(this).attr({"i":i,"s":i});//i:当前,s:初始
				});
				head.children().each(function(newIndex){
					if($(this).children("strong:first").html()=="操作")
						return;
					//找到属于这个位置的TD
					var td = tds.filter("[s='"+$(this).attr("index")+"']:first");
					if(td.size()==0)
						return;
					var oldIndex = parseInt(td.attr("i"));
					var isMove = oldIndex != newIndex;
					var isHide = $(this).is(":hidden");
					if(isMove || isHide){
						trs.each(function(i){
							var childTds = $(this).children("td");
							var oldTd = $(childTds[oldIndex]);
							if(isHide){
								oldTd.hide();
							}
							if(isMove){
				        		//需要排序
		        				$(childTds[newIndex]).before(oldTd);
			        		}
						});
						if(isMove){
							tds = firstTr.children("td");
							tds.each(function(i){
								$(this).attr({"i":i});
							});
						}
					}
				});
				head.children().each(function(i){
					if($(this).children("strong:first").html()=="操作")
						return;
					var thisTd = tds.eq(i);
					if(thisTd.size()==0)
						return false;
					if(maxAutoWidth)
						thisTd.attr("width",$(this).width());
					else
						thisTd.attr("width",$(this).attr("width"));
				});
				
				trs.each(function(){
	   				$(this).find("input[type='button'][onclick]:first").parents("td:first").hide();	
	   				$(this).children("td").each(function(){
						if(CONTROL.option.overHide){
							var childInner = $(this).children(":first");
							if(childInner.size()==0)
								$(this).addClass("overHide").attr("title",$(this).html()=="&nbsp;" ? "" :$.trim($(this).html()));
							else
								$(this).addClass("overHide").attr("title",childInner.html()=="&nbsp;" ? "" :$.trim(childInner.html()));
						}else
							$(this).attr("style","word-WRAP:break-word;"+($(this).attr("style") ? $(this).attr("style") : ""));
					})
	        	});
				
				//添加单击事件，默认
	            gridTable.find("tr"+(CONTROL.option.exceptFirstRow ? ":gt(0)":"")+(CONTROL.option.exceptLastRow ? ":not(:last)":"")).click(function(e){
	            	rowClickEvent(e,$(this));
	            }).contextmenu(function(e){
	            	rowClickEvent(e,$(this));
	            	e.preventDefault();
	            }).dblclick(function(e){
	            	e.preventDefault();
	            	$("#jefActionRow_RightMenu").hide();
	            	eval($(this).find("input[type='button'][onclick]:first").attr("onclick"));
	            });
			}
			trSum = $("#trSum",gridTable);
			moveSum = trSum.size()==1;
    		$("#trSum:first",gridHead).remove();
        	if(moveSum){
        		//需要把总计挪至页面下方
				trSum.attr({"bgcolor":"#f1f1f1","height":"30"});
				trSum.appendTo($("table:first",gridHead));
        	} 
			pager = $("tr:last",gridTable);
			//需要把翻页挪至页面下方
			movePager = pager.attr("align")=="right";
			$("#tablePager tr:first").remove();
			if(movePager){
				pager.appendTo("#tablePager").find("td[title]").removeAttr("title");
			}
			//初始化滚动条容器
			CONTROL.refreshHeight();
			$("#divGrid").width($(window).width()).show();
			gridTable.show();
        }
        function rowClickEvent(e,row,isHead){
			$("."+CONTROL.option.selectedClass).removeClass(CONTROL.option.selectedClass);
	    	row.addClass(CONTROL.option.selectedClass);
	    	CONTROL.showMenu(e,isHead);
			e.stopPropagation();
		}
        //控件初始化
        CONTROL.init = function () {
        	if($("body:first").attr("noConfig")=="1"){
        		//不需要配置
	        	CONTROL.option.dragSize=false;
        		CONTROL.option.dragType="";
        		CONTROL.option.configColumn=false;
        	}
        	
        	//初始化样式和浮动层
			if($("#actionRowStyle").size()==0){
				$("head:first").append('<style type="text/css" id="actionRowStyle">.jefActionRow{background-color:#C0C0C0;} .jefActionRow_RightMenu{position: absolute;display:none;z-index: 99991;width:100px;overflow: hidden;background-color:white;border:solid 1px gray;} .jefActionRow_RightMenu div{border-bottom:dashed 1px gray;padding:5px;} .jefActionRow_HoverItem{color:#fff;font-weight:bolder;background-color: #3399FE;}</style>');
				if($("#jefActionRow_RightMenu").size()==0){
		     		$("body:first").append('<div id="jefActionRow_RightMenu" class="'+CONTROL.option.floatMenuDivClass+'"></div>').click(function(){
		     			$("."+CONTROL.option.selectedClass).removeClass(CONTROL.option.selectedClass);
		     			$("#jefActionRow_RightMenu").hide();
		     		});
		    	}
			}
            //为适应当前框架，少改代码，写的代码
            if(CONTROL.option.autoCreateItem){
            	$("#gridHead tr:first").find("strong").each(function(){
    				if($(this).html()=="操作"){
    					$(this).parent().hide();
    					return false;
    				}
    			});
			}
            gridHead = $("#gridHead").show();
            //超长自动隐藏
            if(CONTROL.option.overHide){
            	$("head:first").append("<style>.overHide{overflow:hidden;white-space: nowrap;}</style>");
            }
            /***************把分页栏挪至页面底部以及可拖拽头部代码开始（此处因为时间太紧所以就写一起了，其实可以抽离一下）**********/
            if(CONTROL.option.autoSize && gridHead.size()==1){
				var maxAutoWidth = $("td[width]:first",gridHead).attr("width").indexOf("%") == -1;
				var dragArray=new Array(0);
				if(CONTROL.option.dragType=='cookie'){
					//读取COOKIE记录拖拽后的宽度
					var cookieValue = CONTROL.getCookie(CONTROL.option.key);
					if(cookieValue!=""){
						try{
							dragArray=eval(cookieValue.replace(/@/g, ","));
						}catch(exception){}
					}
				}
				$("tr",gridHead).each(function(i){
					$(this).children("td").each(function(){
						if(CONTROL.option.overHide){
							$(this).addClass("overHide");
						}else
							$(this).attr("style","word-WRAP:break-word;"+($(this).attr("style") ? $(this).attr("style") : ""));
					})
				});
				$(parent.document).find(".panel-body").css("overflow","hidden");
				$("html,body").css("overflow","hidden");
				var tableWidth=0;
				//需要自适应宽度
				if(maxAutoWidth){
					$("tr:first",gridHead).children().each(function(index){
						if($(this).children().html()=="操作")
							return;
						if(CONTROL.option.dragType!=''){
							//读取COOKIE记录拖拽后的宽度
							for(var i=0;i<dragArray.length;i++){
								if(parseInt(dragArray[i].i)==index){
									$(this).attr("width",dragArray[i].w);
									dragArray[i]=dragArray[dragArray.length-1];
									dragArray.length=dragArray.length-1;
									break;
								}
							}
						}
						if(!CONTROL.option.configColumn || $(this).is(":visible"))
							tableWidth+=$(this).attr("width").indexOf("%")==-1 ? parseInt($(this).attr("width")):$(this).width();
					});
					$("table:first",gridHead).css("width",tableWidth+"px");
				}
				head = $("tr:first",gridHead);
				moveHead = true;
				
				//存在数据,需要挪动头部
				if(moveHead){
					if(maxAutoWidth){
						$("#divGrid").scroll(function(){
							gridHead.css("margin-left",(0-$("#divGrid").scrollLeft())+"px");
							if ($.browser.msie) { 
								setTimeout(function(){gridHead.css("margin-left",(0-$("#divGrid").scrollLeft())+"px");},200);
							}
						});
					}
					if(CONTROL.option.configColumn){
						if(CONTROL.option.dragType=='cookie'){
							//读取COOKIE记录拖拽后的宽度
							var cookieValue = CONTROL.getCookie(CONTROL.option.key);
							if(cookieValue!=""){
								try{
									dragArray=eval(cookieValue.replace(/@/g, ","));
								}catch(exception){}
							}
						}
						var color="";
						var hasDrag=CONTROL.option.dragType!='' && dragArray.length>0;
						$("tr:first td",gridHead).css({"cursor":"pointer"}).attr("title","点击配置显示/隐藏列").hover(function(){
							color=$(this).css("color");
							$(this).css("color","red");
						},function(){
							$(this).css("color",color);
						}).each(function(i){
							if($(this).children().html()=="操作")
								return;
							CONTROL.option.maxIndex=i;
							var loopTd=$(this);
							loopTd.attr({"index":i,"i":i}).click(function(e){
				            	rowClickEvent(e,loopTd,true);
				            }).contextmenu(function(e){
				            	rowClickEvent(e,loopTd,true);
				            	e.preventDefault();
				            });
							if(hasDrag){
								var isSet=false;
								//读取COOKIE记录拖拽后的宽度
								for(var j=0;j<dragArray.length;j++){
									if(parseInt(dragArray[j].i)==i){
										if(dragArray[j].d){
											CONTROL.changeColumn(loopTd);
										}
										if(typeof(dragArray[j].o)!="undefined"){
											loopTd.attr("o",dragArray[j].o);
											isSet=true;
										}
										dragArray[j]=dragArray[dragArray.length-1];
										dragArray.length=dragArray.length-1;
										break;
									}
								}
								if(!isSet){
									loopTd.attr("o",i);
								}
							}
						});
            			if(hasDrag){
							CONTROL.orderColumn();
						}
					}
				}
				/*********************拖拽，只能适应不是百分比的页面 start*********************/
				if(maxAutoWidth && CONTROL.option.dragSize){
					var mPressed=false;
					var startX=0;
					var eventTd=false;
					var startWidth=0;
					var startTableWidth = 0;
					var eventColumn = false;
					$("strong",gridHead).each(function(i){
						$(this).before("<span class='columnResize' min='"+($(this).html().length*12+20)+"'>&nbsp;</span>");
					});
					$(".columnResize").bind('selectstart', function () {
				        return false;
				    }).click(function () {
				        return false;
				    }).dblclick(function () {
				        //双击事件
				        mPressed = false;
				        return false;
				    }).mousedown(function (event) {
				        if (event.which != 1)
				            return false;
				        //鼠标按下事件,执行拖拽
				        mPressed = true;
				        startX=event.pageX;
				        eventTd=$(this).parent();
				        startWidth=eventTd.width();
				        startTableWidth=$("table:first",gridHead).width();
				        eventColumn = $(this);
				        var moveDrag = function(e){
				        	if(mPressed){
				        		var width = startWidth+(e.pageX-startX);
				        		if(width>parseInt(eventColumn.attr("min"))){
				        			eventTd.width(width);
					        		$("tr:first",gridTable).children(":eq("+eventTd.attr("i")+")").width(width);
					        		width = startTableWidth+(e.pageX-startX);
					        		$("table:first",gridHead).width(width);
					        		gridTable.width(width);
				        		}else{
				        			width = parseInt(eventColumn.attr("min"));
				        			eventTd.width(width);
					        		$("tr:first",gridTable).children(":eq("+eventTd.attr("i")+")").width(width);
					        		width = startTableWidth-startWidth+width;
					        		$("table:first",gridHead).width(width);
					        		gridTable.width(width);
				        		}
				        		CONTROL.refreshHeight();
				        	}
				        };
				        var endDrag = function(e){
				        	if(CONTROL.option.dragType=='cookie'){
				        		//COOKIE记录拖拽
				       			CONTROL.putCookie(eventTd);		
				        	}
				        	CONTROL.refreshHeight();
				       		$(document).unbind("mousemove",moveDrag).unbind("mouseup", endDrag).unbind('selectstart',selectDrag);
				       		mPressed=false;startX=0;eventTd=false;startWidth=0;startTableWidth = 0;eventColumn = false;
				        };
				        var selectDrag =function(){
				        	return false;
				        }
				        $(document).bind("mousemove",moveDrag).bind("mouseup", endDrag).bind('selectstart',selectDrag);
				        return false;
				    });
				}
			}
            if(CONTROL.option.configColumn){
            	if($("#divAjaxBG").length==0){
					$(document.body).append("<div id='divAjaxBG' style='display: none; background-color: black; position: absolute; z-index: 9990; filter: Alpha(opacity=20); opacity: 0.2; left: 0px; top: 0px;'>透明层</div><div id='divAjax' style='position: absolute;  z-index: 9999;display: none;text-align: center;width:458px;border:solid gray 5px;background-color:white;'><table cellpadding='0' border='0' cellspacing='0' width='100%'><td width='200'><div style='overflow-x:hidden;overflow-y:auto;width:200px;text-align:left;' box='left'></div></td><td width='60' style='border-left:1px solid gray;border-right:1px solid gray;vertical-align:middle;text-align:center;'><input type='button' class='btn' style='margin:0px;font-family:NSimSun;' value='&gt;&gt;' title='全部隐藏'/><br/><br/><input type='button' class='btn' style='margin:0px;font-family:NSimSun;' value='&lt;&lt;' title='全部显示'/></td><td width='200'><div style='overflow-x:hidden;overflow-y:auto;width:200px;text-align:left;' box='right'></div></td></table><div button='1' style='padding:5px;border-top:solid gray 1px;'><input type='button' class='btn btn-primary' value='保存'/><input type='button' class='btn' value='返回'/></div></div>");
	            	$("head:first").append('<style type="text/css">.allowDrag{cursor: pointer;} .startDrag{border-bottom: dashed 2px Green;} .tdDrag{border-bottom: dashed 2px Red;} #drag_container{background: #ffffff;color: #000;z-index: 99999;font: normal 11px arial, tahoma, helvetica, sans-serif;border: 1px dashed #767676;}</style>');
            	}
				$("#divAjax :button:not([title])").click(function(){
            		if($(this).attr("value")=="保存"){
            			CONTROL.hideConfigColumn();
            			if($("#divAjax table[table='left']:first tr:gt(0)").size()==0){
            				top.j_tip("至少应该存在一列显示信息(请重新操作后进行保存)", 'error');
            				return;
            			}
            			var headTds =$("tr:first td",gridHead);
            			var loop=0;
            			$("#divAjax table[table]").each(function(){
            				var type = $(this).attr("table");
        					$(this).find("td").each(function(){
        						if(type=="left"){
	        						if($(this).attr("d")=="1"){
	        							CONTROL.changeColumn(headTds.filter("[index='"+$(this).attr("index")+"']:first"),true);
	        						}
        						}else{
        							if($(this).attr("d")=="0")
	        							CONTROL.changeColumn(headTds.filter("[index='"+$(this).attr("index")+"']:first"));
        						}
    							headTds.filter("[index='"+$(this).attr("index")+"']:first").attr("o",loop);
        						//判断是否需要移动列的位置
        						loop++;
        					});
            			});
            			CONTROL.orderColumn();
            			if(CONTROL.option.dragType=='cookie'){
							CONTROL.orderCookie();
						}
            		}
            		CONTROL.hideConfigColumn();
            	});
				$("#divAjax :button[title]").click(function(){
					var target = $(this).prop("title")=="全部显示"?"right":"left";
					$("#divAjax table[table='"+target+"']:first tr:gt(0)").appendTo($("#divAjax table[table='"+(target=="left" ? "right":"left")+"']:first"));
            	});
				$(".info_right_ctrl:first").append('<input class="btn" type="button" id="btnColumnDefault" value="配置列恢复默认设置" />');
				$("#btnColumnDefault").click(function(){
					if(CONTROL.option.dragType=='cookie'){
						CONTROL.deleteCookie(CONTROL.option.key);
					}
					window.location.reload(); 
				});
            }
            if(typeof(CONTROL.option.afterInit) == "function"){
				CONTROL.option.afterInit(CONTROL);
			}
        };
        CONTROL.init();
    });
}
